/**
 *******************************************************************************
 * @FileName  : lg_mem.h
 * @Author    : GaoQiu
 * @CreateDate: 2020-09-10
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
#ifndef _LG_MEM_H
#define _LG_MEM_H

//#include <stdint.h>
//#include <stddef.h>
#include "utils/defs_types.h"

#ifdef __cplusplus
extern "C" {
#endif

#define LG_SYS_HEAP_EN   0

#if LG_SYS_HEAP_EN
extern char _end_bss_[];
extern char __irq_stack_end[];
//#define LG_MEM_SIZE  (uint32_t)(0x0084FB00 - (uint32_t)&_end_bss_[0])
#define LG_MEM_SIZE  (uint32_t)(0x0084FB00 - (uint32_t)&__irq_stack_end[0])
#else
#define LG_MEM_SIZE  (4*1024)  /*!!! must MEM_ALIGN */
#endif

#define LG_MEM_MIN_BLOCK_SIZE  16
#define MEM_ALIGN              4

typedef uint16_t lg_size_t;


/**
 * Calculate memory size for an aligned buffer.
 */
#ifndef MEM_ALIGN_SIZE
#define MEM_ALIGN_SIZE(size)  (((size) + MEM_ALIGN - 1) & ~(MEM_ALIGN-1))
#endif

#define lg_log                MEM_TRACK_ERR

void lg_mem_init(void);
void *lg_mem_new(uint32_t size);
int lg_mem_release(void *p);


void lg_mem_usage_info(void);
void lg_mem_debug();

#ifdef __cplusplus
};
#endif

#endif
